package edu.neelsys.business.usercourse;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import edu.neelsys.objectmodel.dbentites.UserCourse;
import edu.neelsys.objectmodel.userauth.LoggedUser;
import edu.neelsys.repository.usercourse.UserCourseRepository;

@Service
@Transactional(readOnly = true)
public class UserCourseBean {

	@Autowired
	UserCourseRepository userCourseRepository;

	@Transactional
	public List<UserCourse> findCoursesByUser(String userName) {

		LoggedUser loggedUser = (LoggedUser) SecurityContextHolder.getContext()
				.getAuthentication().getPrincipal();

		return userCourseRepository.findCoursesByUser(loggedUser.getUser());

	}
}
